package com.itheima.patterns.builderpattern.prototype.deepcopy2;

public class Person implements Cloneable {
    private int id;
    private String name;
    private Address address;
    
    public String getName() {
        return name;
    }
    
    public Person(int id, String name, Address address) {
        this.id = id;
        this.name = name;
        this.address = address;
        System.out.println("具体的原型对象创建完成！");
    }
    
    @Override
    public Object clone() throws CloneNotSupportedException {
        System.out.println("具体原型复制成功！");
        Person person = null;
        person = (Person)super.clone();
        //对引用数据类型单独处理
        person.name = new String(name);
        person.address = (Address)address.clone();
        return person;
    }
    
    @Override
    public String toString() {
        return "Person{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", address=" + address +
                '}';
    }
}